Remove generic infrastrucure for printing json
authorAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 30 Jan 2017 19:53:05 +0000 (22:53 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 30 Jan 2017 19:53:05 +0000 (22:53 +0300)
 Only a couple of command really use this features, so it's clearer just to print json right on the spot rather then return it though the call stack.

34 files changed:
src/bin/bench.rs
src/bin/build.rs
src/bin/cargo.rs
src/bin/check.rs
src/bin/clean.rs
src/bin/doc.rs
src/bin/fetch.rs
src/bin/generate_lockfile.rs
src/bin/git_checkout.rs
src/bin/help.rs
src/bin/init.rs
src/bin/install.rs
src/bin/locate_project.rs
src/bin/login.rs
src/bin/metadata.rs
src/bin/new.rs
src/bin/owner.rs
src/bin/package.rs
src/bin/pkgid.rs
src/bin/publish.rs
src/bin/read_manifest.rs
src/bin/run.rs
src/bin/rustc.rs
src/bin/rustdoc.rs
src/bin/search.rs
src/bin/test.rs
src/bin/uninstall.rs
src/bin/update.rs
src/bin/verify_project.rs
src/bin/version.rs
src/bin/yank.rs
src/cargo/lib.rs
src/cargo/util/errors.rs
tests/version.rs

index 5f03bf9119f8b829daf016d82e640aca6b67ec03..ffca42abed02938fd5f97f68a0ff75edf1a34699 100644 (file)
@@ -70,7 +70,7 @@ not affect how many jobs are used when running the benchmarks.
 Compilation can be customized with the `bench` profile in the manifest.
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
     config.configure(options.flag_verbose,
                      options.flag_quiet,
@@ -105,7 +105,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     let ws = Workspace::new(&root, config)?;
     let err = ops::run_benches(&ws, &ops, &options.arg_args)?;
     match err {
-        None => Ok(None),
+        None => Ok(()),
         Some(err) => {
             Err(match err.exit.as_ref().and_then(|e| e.code()) {
                 Some(i) => CliError::new(human("bench failed"), i),
index 9b7ffc7c0bb7b584ee346e255c9282b8d0c004f2..13639c1aa28acb68949349e7256afa059fe50a27 100644 (file)
@@ -71,7 +71,7 @@ the manifest. The default profile for this command is `dev`, but passing
 the --release flag will use the `release` profile instead.
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     debug!("executing; cmd=cargo-build; args={:?}",
            env::args().collect::<Vec<_>>());
     config.configure(options.flag_verbose,
@@ -110,5 +110,5 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
 
     let ws = Workspace::new(&root, config)?;
     ops::compile(&ws, &opts)?;
-    Ok(None)
+    Ok(())
 }
index 3fc95ffe4d863726261547f8d907ae04f93f1524..e417cf5683c0068fbe67718cfbb7a1bdb35994de 100644 (file)
@@ -89,8 +89,7 @@ fn main() {
 
     match result {
         Err(e) => cargo::handle_cli_error(e, &mut *config.shell()),
-        Ok(None) => {},
-        Ok(Some(())) => unreachable!(),
+        Ok(()) => {},
     }
 }
 
@@ -139,7 +138,7 @@ each_subcommand!(declare_mod);
   because they are fundamental (and intertwined). Other commands can rely
   on this top-level information.
 */
-fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
+fn execute(flags: Flags, config: &Config) -> CliResult {
     config.configure(flags.flag_verbose,
                      flags.flag_quiet,
                      &flags.flag_color,
@@ -162,7 +161,7 @@ fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
                 }
             }
         }
-        return Ok(None)
+        return Ok(())
     }
 
     if flags.flag_list {
@@ -170,13 +169,13 @@ fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
         for command in list_commands(config) {
             println!("    {}", command);
         };
-        return Ok(None)
+        return Ok(())
     }
 
     if let Some(ref code) = flags.flag_explain {
         let mut procss = config.rustc()?.process();
         procss.arg("--explain").arg(code).exec().map_err(human)?;
-        return Ok(None)
+        return Ok(())
     }
 
     let args = match &flags.arg_command[..] {
@@ -189,7 +188,7 @@ fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
             let r = cargo::call_main_without_stdin(execute, config, USAGE, args,
                                                    false);
             cargo::process_executed(r, &mut config.shell());
-            return Ok(None)
+            return Ok(())
         }
 
         // For `cargo help -h` and `cargo help --help`, print out the help
@@ -221,7 +220,7 @@ fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
     };
 
     if try_execute(&config, &args) {
-        return Ok(None)
+        return Ok(())
     }
 
     let alias_list = aliased_command(&config, &args[1])?;
@@ -233,7 +232,7 @@ fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
                 .map(|s| s.to_string())
                 .collect::<Vec<_>>();
             if try_execute(&config, &chain) {
-                return Ok(None)
+                return Ok(())
             } else {
                 chain
             }
@@ -241,7 +240,7 @@ fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
         None => args,
     };
     execute_subcommand(config, &args[1], &args)?;
-    Ok(None)
+    Ok(())
 }
 
 fn try_execute(config: &Config, args: &[String]) -> bool {
@@ -298,7 +297,7 @@ fn find_closest(config: &Config, cmd: &str) -> Option<String> {
 
 fn execute_subcommand(config: &Config,
                       cmd: &str,
-                      args: &[String]) -> CliResult<()> {
+                      args: &[String]) -> CliResult {
     let command_exe = format!("cargo-{}{}", cmd, env::consts::EXE_SUFFIX);
     let path = search_directories(config)
                     .iter()
index d8c4a7027ef94405f4f6ebf1209a8d8a93a66253..de8a9c6040cfe5b368b687811bea8a3158ed3e6d 100644 (file)
@@ -66,7 +66,7 @@ pub struct Options {
     flag_frozen: bool,
 }
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     debug!("executing; cmd=cargo-check; args={:?}",
            env::args().collect::<Vec<_>>());
 
@@ -100,5 +100,5 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     };
 
     ops::compile(&ws, &opts)?;
-    Ok(None)
+    Ok(())
 }
index 482e891978cbca83edc87532ac6fea4b8ef9a3aa..8903f89031297e9fa24a00d0d75a5dfda3a1791b 100644 (file)
@@ -42,7 +42,7 @@ given, then all packages' artifacts are removed. For more information on SPEC
 and its format, see the `cargo help pkgid` command.
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     debug!("executing; cmd=cargo-clean; args={:?}", env::args().collect::<Vec<_>>());
     config.configure(options.flag_verbose,
                      options.flag_quiet,
@@ -59,5 +59,5 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     };
     let ws = Workspace::new(&root, config)?;
     ops::clean(&ws, &opts)?;
-    Ok(None)
+    Ok(())
 }
index 5323b4adb0b2404c11917dd27014f8c72dda8992..edbb9b2eccdfa83266dd206a1ee7edc577bd7df0 100644 (file)
@@ -66,7 +66,7 @@ current package is documented. For more information on SPEC and its format, see
 the `cargo help pkgid` command.
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     config.configure(options.flag_verbose,
                      options.flag_quiet,
                      &options.flag_color,
@@ -109,5 +109,5 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
 
     let ws = Workspace::new(&root, config)?;
     ops::doc(&ws, &doc_opts)?;
-    Ok(None)
+    Ok(())
 }
index 01bca5f51546a2f1b2446862f95461928fc225f9..80aba98db928456eeabee9451a0355694d5a6446 100644 (file)
@@ -38,7 +38,7 @@ If the lockfile is not available, then this is the equivalent of
 all updated.
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     config.configure(options.flag_verbose,
                      options.flag_quiet,
                      &options.flag_color,
@@ -47,6 +47,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
     let ws = Workspace::new(&root, config)?;
     ops::fetch(&ws)?;
-    Ok(None)
+    Ok(())
 }
 
index 70365505fe4947b85712ed80d11465850ac441a3..f545b1e26f70662e377d43e5f455ae9864524d1e 100644 (file)
@@ -31,7 +31,7 @@ Options:
     --locked                 Require Cargo.lock is up to date
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     debug!("executing; cmd=cargo-generate-lockfile; args={:?}", env::args().collect::<Vec<_>>());
     config.configure(options.flag_verbose,
                      options.flag_quiet,
@@ -42,5 +42,5 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
 
     let ws = Workspace::new(&root, config)?;
     ops::generate_lockfile(&ws)?;
-    Ok(None)
+    Ok(())
 }
index f2e9f609159c287e8332c3a4868583fb98e15f06..4309f0163fed51dce746bd677d1c428f1f65f3e5 100644 (file)
@@ -29,7 +29,7 @@ Options:
     --locked                 Require Cargo.lock is up to date
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     config.configure(options.flag_verbose,
                      options.flag_quiet,
                      &options.flag_color,
@@ -46,5 +46,5 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
 
     source.update()?;
 
-    Ok(None)
+    Ok(())
 }
index 8597bd5943925b99a1203fa64b14ba9bb3449306..a068b0a2c63bddf660d7e62fc1ae09bd60168963 100644 (file)
@@ -14,7 +14,7 @@ Options:
     -h, --help          Print this message
 ";
 
-pub fn execute(_: Options, _: &Config) -> CliResult<Option<()>> {
+pub fn execute(_: Options, _: &Config) -> CliResult {
     // This is a dummy command just so that `cargo help help` works.
     // The actual delegation of help flag to subcommands is handled by the
     // cargo command.
index d585ce03dfad053ab7cef6d2d3d7a21b62aaa440..336ebe387cb703d222fa8af35ea9c38b2ac00cb5 100644 (file)
@@ -39,7 +39,7 @@ Options:
     --locked            Require Cargo.lock is up to date
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     debug!("executing; cmd=cargo-init; args={:?}", env::args().collect::<Vec<_>>());
     config.configure(options.flag_verbose,
                      options.flag_quiet,
@@ -63,6 +63,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
                                              if opts_lib { "library" }
                                              else {"binary (application)"}))?;
 
-    Ok(None)
+    Ok(())
 }
 
index 93bfe631998afd4e2167e61bf95714714cafc583..41781a5a51d62a154308708295547b05ba1fe783 100644 (file)
@@ -94,7 +94,7 @@ the more explicit `install --path .`.
 The `--list` option will list all installed packages (and their versions).
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     config.configure(options.flag_verbose,
                      options.flag_quiet,
                      &options.flag_color,
@@ -147,5 +147,5 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     } else {
         ops::install(root, krate, &source, vers, &compile_opts, options.flag_force)?;
     }
-    Ok(None)
+    Ok(())
 }
index c9a352453f23b936aee3ed82124ccd47be20c805..d89f6526920eafd9b72ef6ee9e33c08355e01bd3 100644 (file)
@@ -1,3 +1,4 @@
+use cargo;
 use cargo::util::{CliResult, CliError, human, ChainError, Config};
 use cargo::util::important_paths::{find_root_manifest_for_wd};
 
@@ -23,7 +24,7 @@ pub struct ProjectLocation {
 }
 
 pub fn execute(flags: LocateProjectFlags,
-               config: &Config) -> CliResult<Option<ProjectLocation>> {
+               config: &Config) -> CliResult {
     let root = find_root_manifest_for_wd(flags.flag_manifest_path, config.cwd())?;
 
     let string = root.to_str()
@@ -32,5 +33,7 @@ pub fn execute(flags: LocateProjectFlags,
                                              Unicode"))
                       .map_err(|e| CliError::new(e, 1))?;
 
-    Ok(Some(ProjectLocation { root: string.to_string() }))
+    let location = ProjectLocation { root: string.to_string() };
+    cargo::print_json(&location);
+    Ok(())
 }
index 1202c82aaa8bcdfc9e7ba9220d5d6548b33dea2a..7e575f47df41f9005bb7bf8723521e61499294db 100644 (file)
@@ -34,7 +34,7 @@ Options:
 
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     config.configure(options.flag_verbose,
                      options.flag_quiet,
                      &options.flag_color,
@@ -60,6 +60,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
 
     let token = token.trim().to_string();
     ops::registry_login(config, token)?;
-    Ok(None)
+    Ok(())
 }
 
index f7be16c575f15775564f886b1eb677d73521802e..b96e641e29ae83300e1ca3d86b822616293d7532 100644 (file)
@@ -1,5 +1,6 @@
+use cargo;
 use cargo::core::Workspace;
-use cargo::ops::{output_metadata, OutputMetadataOptions, ExportInfo};
+use cargo::ops::{output_metadata, OutputMetadataOptions};
 use cargo::util::important_paths::find_root_manifest_for_wd;
 use cargo::util::{CliResult, Config};
 
@@ -42,7 +43,7 @@ Options:
     --locked                   Require Cargo.lock is up to date
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<ExportInfo>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     config.configure(options.flag_verbose,
                      options.flag_quiet,
                      &options.flag_color,
@@ -60,5 +61,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<ExportInfo
 
     let ws = Workspace::new(&manifest, config)?;
     let result = output_metadata(&ws, &options)?;
-    Ok(Some(result))
+    cargo::print_json(&result);
+    Ok(())
 }
index d0bd8103973fd4f1cf82e2f0ace6be53ee60e111..716c983db4c212a464887d3c0e61914aee34f905 100644 (file)
@@ -39,7 +39,7 @@ Options:
     --locked            Require Cargo.lock is up to date
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     debug!("executing; cmd=cargo-new; args={:?}", env::args().collect::<Vec<_>>());
     config.configure(options.flag_verbose,
                      options.flag_quiet,
@@ -63,6 +63,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
                                              else {"binary (application)"},
                                              arg_path))?;
 
-    Ok(None)
+    Ok(())
 }
 
index 10fd84f8c2e05da8e4f14ef21d134b9d261c75cf..288d13e302c0e24da379d121c2ecf1a44d201e12 100644 (file)
@@ -44,7 +44,7 @@ See http://doc.crates.io/crates-io.html#cargo-owner for detailed documentation
 and troubleshooting.
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     config.configure(options.flag_verbose,
                      options.flag_quiet,
                      &options.flag_color,
@@ -59,6 +59,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
         list: options.flag_list,
     };
     ops::modify_owners(config, &opts)?;
-    Ok(None)
+    Ok(())
 }
 
index 0292bb7ba99c72d5c55cf5d15ef67100438472ed..df342fbf8bfc697a7f692ec25c0f6ab0be20e4f8 100644 (file)
@@ -39,7 +39,7 @@ Options:
     --locked                Require Cargo.lock is up to date
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     config.configure(options.flag_verbose,
                      options.flag_quiet,
                      &options.flag_color,
@@ -55,5 +55,5 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
         allow_dirty: options.flag_allow_dirty,
         jobs: options.flag_jobs,
     })?;
-    Ok(None)
+    Ok(())
 }
index 536cfa1990625419e81759ec046cf199b41c4f92..ea573361d9e8bccfdb02871ce3ac63ec4b0491a0 100644 (file)
@@ -53,7 +53,7 @@ Example Package IDs
 ";
 
 pub fn execute(options: Options,
-               config: &Config) -> CliResult<Option<()>> {
+               config: &Config) -> CliResult {
     config.configure(options.flag_verbose,
                      options.flag_quiet,
                      &options.flag_color,
@@ -72,6 +72,6 @@ pub fn execute(options: Options,
     let spec = spec.as_ref().map(|s| &s[..]);
     let spec = ops::pkgid(&ws, spec)?;
     println!("{}", spec);
-    Ok(None)
+    Ok(())
 }
 
index 1228b294e1497be041989eb93aa2a940fcff11f9..dcba4df07e27c53839ee85a7eda91760ac463263 100644 (file)
@@ -42,7 +42,7 @@ Options:
 
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     config.configure(options.flag_verbose,
                      options.flag_quiet,
                      &options.flag_color,
@@ -70,5 +70,5 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
         jobs: jobs,
         dry_run: dry_run,
     })?;
-    Ok(None)
+    Ok(())
 }
index a663cda4a7abffdcadf9fcff4b3f284560615c32..07c4a5f2c455d013e687eadb7ca956f2926bc954 100644 (file)
@@ -1,5 +1,6 @@
 use std::env;
 
+use cargo;
 use cargo::core::Package;
 use cargo::util::{CliResult, Config};
 use cargo::util::important_paths::{find_root_manifest_for_wd};
@@ -25,7 +26,7 @@ Options:
     --color WHEN             Coloring: auto, always, never
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<Package>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     debug!("executing; cmd=cargo-read-manifest; args={:?}",
            env::args().collect::<Vec<_>>());
     config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))?;
@@ -33,5 +34,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<Package>>
     let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
 
     let pkg = Package::for_path(&root, config)?;
-    Ok(Some(pkg))
+    cargo::print_json(&pkg);
+    Ok(())
 }
index 0bb293d9d4fcfea802bb6285206ed7383c3984e8..79a0a326f1aa3bebc0b49d60c9b08e42224e1214 100644 (file)
@@ -57,7 +57,7 @@ arguments to both Cargo and the binary, the ones after `--` go to the binary,
 the ones before go to Cargo.
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     config.configure(options.flag_verbose,
                      options.flag_quiet,
                      &options.flag_color,
@@ -99,7 +99,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
 
     let ws = Workspace::new(&root, config)?;
     match ops::run(&ws, &compile_opts, &options.arg_args)? {
-        None => Ok(None),
+        None => Ok(()),
         Some(err) => {
             // If we never actually spawned the process then that sounds pretty
             // bad and we always want to forward that up.
index d812e5eb5b22b4a3d956fd11e661e1921a45fff4..bff80feceec627466b0332d5bd0c1077f519da1e 100644 (file)
@@ -73,7 +73,7 @@ processes spawned by Cargo, use the $RUSTFLAGS environment variable or the
 `build.rustflags` configuration option.
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     debug!("executing; cmd=cargo-rustc; args={:?}",
            env::args().collect::<Vec<_>>());
     config.configure(options.flag_verbose,
@@ -120,6 +120,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
 
     let ws = Workspace::new(&root, config)?;
     ops::compile(&ws, &opts)?;
-    Ok(None)
+    Ok(())
 }
 
index 7df9a27abcc10de434f37c8a5fd2d688359656e2..d82bc3e7e9cd9e3c8e2001dc9a21f30014424e16 100644 (file)
@@ -70,7 +70,7 @@ current package is documented. For more information on SPEC and its format, see
 the `cargo help pkgid` command.
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     config.configure(options.flag_verbose,
                      options.flag_quiet,
                      &options.flag_color,
@@ -108,5 +108,5 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     let ws = Workspace::new(&root, config)?;
     ops::doc(&ws, &doc_opts)?;
 
-    Ok(None)
+    Ok(())
 }
index 5bc518f659f9e7845852bbdbcf0dd4d6b240c23d..47879cae5824451192f535b8fea4a3a5966487ad 100644 (file)
@@ -33,7 +33,7 @@ Options:
     --locked                 Require Cargo.lock is up to date
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     config.configure(options.flag_verbose,
                      options.flag_quiet,
                      &options.flag_color,
@@ -47,5 +47,5 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     } = options;
 
     ops::search(&query.join("+"), config, host, cmp::min(100, limit.unwrap_or(10)) as u8)?;
-    Ok(None)
+    Ok(())
 }
index 59bf0a09d1fae21aad98d3e1d8c8adec367512c2..5f7f9eb8cf7998dc3b92ad15dc33647d8e03e3e0 100644 (file)
@@ -93,7 +93,7 @@ To get the list of all options available for the test binaries use this:
   cargo test -- --help
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     config.configure(options.flag_verbose,
                      options.flag_quiet,
                      &options.flag_color,
@@ -146,7 +146,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     let ws = Workspace::new(&root, config)?;
     let err = ops::run_tests(&ws, &ops, &options.arg_args)?;
     match err {
-        None => Ok(None),
+        None => Ok(()),
         Some(err) => {
             Err(match err.exit.as_ref().and_then(|e| e.code()) {
                 Some(i) => CliError::new(human("test failed"), i),
index 9f3c33af121bbb686ca976735bbb1d9ba83251c0..725452251e1812a2a508892ca36884f8eed347af 100644 (file)
@@ -37,7 +37,7 @@ uninstalled for a crate but the `--bin` and `--example` flags can be used to
 only uninstall particular binaries.
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     config.configure(options.flag_verbose,
                      options.flag_quiet,
                      &options.flag_color,
@@ -46,6 +46,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
 
     let root = options.flag_root.as_ref().map(|s| &s[..]);
     ops::uninstall(root, &options.arg_spec, &options.flag_bin, config)?;
-    Ok(None)
+    Ok(())
 }
 
index ede94bb0f79fa6e475f3b084d2f93aa2806ee313..e8da2bd5cbcf870817d801433037e294549ff7b0 100644 (file)
@@ -57,7 +57,7 @@ updated.
 For more information about package id specifications, see `cargo help pkgid`.
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     debug!("executing; cmd=cargo-update; args={:?}", env::args().collect::<Vec<_>>());
     config.configure(options.flag_verbose,
                      options.flag_quiet,
@@ -75,5 +75,5 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
 
     let ws = Workspace::new(&root, config)?;
     ops::update_lockfile(&ws, &update_opts)?;
-    Ok(None)
+    Ok(())
 }
index be498942a1b2943001b03ffaf353dad4f12e483d..882873d1f1e08b3a3cf17f837e5d3579232efe1a 100644 (file)
@@ -3,13 +3,12 @@ use std::fs::File;
 use std::io::prelude::*;
 use std::process;
 
+use cargo;
 use cargo::util::important_paths::{find_root_manifest_for_wd};
 use cargo::util::{CliResult, Config};
 use rustc_serialize::json;
 use toml;
 
-pub type Error = HashMap<String, String>;
-
 #[derive(RustcDecodable)]
 pub struct Flags {
     flag_manifest_path: Option<String>,
@@ -37,7 +36,7 @@ Options:
     --locked                Require Cargo.lock is up to date
 ";
 
-pub fn execute(args: Flags, config: &Config) -> CliResult<Option<Error>> {
+pub fn execute(args: Flags, config: &Config) -> CliResult {
     config.configure(args.flag_verbose,
                      args.flag_quiet,
                      &args.flag_color,
@@ -63,7 +62,8 @@ pub fn execute(args: Flags, config: &Config) -> CliResult<Option<Error>> {
 
     let mut h = HashMap::new();
     h.insert("success".to_string(), "true".to_string());
-    Ok(Some(h))
+    cargo::print_json(&h);
+    Ok(())
 }
 
 fn fail(reason: &str, value: &str) -> ! {
index d809d1ddd94c75388ded3638657cda1c9a305b9f..9724481036ae4d21a59abd349d5427b14a69968a 100644 (file)
@@ -18,10 +18,10 @@ Options:
     --color WHEN             Coloring: auto, always, never
 ";
 
-pub fn execute(_: Options, _: &Config) -> CliResult<Option<()>> {
+pub fn execute(_: Options, _: &Config) -> CliResult {
     debug!("executing; cmd=cargo-version; args={:?}", env::args().collect::<Vec<_>>());
 
     println!("{}", cargo::version());
 
-    Ok(None)
+    Ok(())
 }
index d7fdf7752977d25f07a63b4c790dba30db974b5d..9e5663684ab8ca121ad16de845fc086baf11c215 100644 (file)
@@ -42,7 +42,7 @@ download the yanked version to use it. Cargo will, however, not allow any new
 crates to be locked to any yanked version.
 ";
 
-pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
+pub fn execute(options: Options, config: &Config) -> CliResult {
     config.configure(options.flag_verbose,
                      options.flag_quiet,
                      &options.flag_color,
@@ -54,6 +54,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
               options.flag_token,
               options.flag_index,
               options.flag_undo)?;
-    Ok(None)
+    Ok(())
 }
 
index 920fb4185ed6e33003ed9660aff692d3956eb011..822b668e27d84e92a0a6b07355cf2d25aec6b28e 100755 (executable)
@@ -104,32 +104,40 @@ impl fmt::Display for VersionInfo {
     }
 }
 
-pub fn call_main_without_stdin<T, V>(
-            exec: fn(T, &Config) -> CliResult<Option<V>>,
+pub fn call_main_without_stdin<Flags: Decodable>(
+            exec: fn(Flags, &Config) -> CliResult,
             config: &Config,
             usage: &str,
             args: &[String],
-            options_first: bool) -> CliResult<Option<V>>
-    where V: Encodable, T: Decodable
+            options_first: bool) -> CliResult
 {
-    let flags = flags_from_args::<T>(usage, args, options_first)?;
+    let docopt = Docopt::new(usage).unwrap()
+        .options_first(options_first)
+        .argv(args.iter().map(|s| &s[..]))
+        .help(true);
+
+    let flags = docopt.decode().map_err(|e| {
+        let code = if e.fatal() {1} else {0};
+        CliError::new(human(e.to_string()), code)
+    })?;
+
     exec(flags, config)
 }
 
 // This will diverge if `result` is an `Err` and return otherwise.
-pub fn process_executed<T>(result: CliResult<Option<T>>, shell: &mut MultiShell)
-    where T: Encodable
+pub fn process_executed(result: CliResult, shell: &mut MultiShell)
 {
     match result {
         Err(e) => handle_cli_error(e, shell),
-        Ok(Some(encodable)) => {
-            let encoded = json::encode(&encodable).unwrap();
-            println!("{}", encoded);
-        }
-        Ok(None) => {}
+        Ok(()) => {}
     }
 }
 
+pub fn print_json<T: Encodable>(obj: &T) {
+    let encoded = json::encode(&obj).unwrap();
+    println!("{}", encoded);
+}
+
 pub fn shell(verbosity: Verbosity, color_config: ColorConfig) -> MultiShell {
     enum Output {
         Stdout,
@@ -275,16 +283,3 @@ pub fn version() -> VersionInfo {
         }
     }
 }
-
-fn flags_from_args<T>(usage: &str, args: &[String], options_first: bool) -> CliResult<T>
-    where T: Decodable
-{
-    let docopt = Docopt::new(usage).unwrap()
-                                   .options_first(options_first)
-                                   .argv(args.iter().map(|s| &s[..]))
-                                   .help(true);
-    docopt.decode().map_err(|e| {
-        let code = if e.fatal() {1} else {0};
-        CliError::new(human(e.to_string()), code)
-    })
-}
index 853b8bef9d5b77d025512532261bc781568bf115..c54199f5b15346771eddd32556b8f2b1a2d0966c 100644 (file)
@@ -243,7 +243,7 @@ impl<E: CargoError> CargoError for Human<E> {
 // =============================================================================
 // CLI errors
 
-pub type CliResult<T> = Result<T, CliError>;
+pub type CliResult = Result<(), CliError>;
 
 #[derive(Debug)]
 pub struct CliError {
index 2171cef5e13e56dc5247c218c47f52f3350618fb..5ace3fa2276f1213e3320387a346bf991181e327 100644 (file)
@@ -20,35 +20,6 @@ fn simple() {
 
 }
 
-#[derive(RustcDecodable)]
-struct FooFlags {
-    flag_version: bool,
-}
-
-fn real_main(flags: FooFlags, _config: &cargo::Config) ->
-        cargo::CliResult<Option<String>> {
-    if flags.flag_version {
-        Ok(Some("foo <version>".to_string()))
-    } else {
-        Ok(None)
-    }
-}
-
-#[test]
-fn subcommand_with_version_using_exec_main_without_stdin() {
-    let usage = "
-Usage: cargo foo [--version]
-
-Options:
-    -V, --version       Print version info
-";
-    let args: Vec<String> = vec!["cargo", "foo", "--version"]
-        .into_iter().map(|s| s.to_string()).collect();
-    let result = cargo::call_main_without_stdin(
-                real_main, &cargo::Config::default().unwrap(),
-                usage, &args, false);
-    assert_eq!(result.unwrap(), Some("foo <version>".to_string()));
-}
 
 #[test]
 #[cfg_attr(target_os = "windows", ignore)]